#!/bin/bash
#/*
 #* com.nathulal.SBSilentToggle
 #* 
 #* Copyright (c) 2009 nathulal <inathulal at gmail.com>. All rights reserved.
 #* 
 #* This file is part of SBSilentToggle.
 #* 
 #* SBSilentToggle is free software: you can redistribute it and/or modify
 #* it under the terms of the GNU General Public License as published by
 #* the Free Software Foundation, either version 3 of the License, or
 #* (at your option) any later version.
 #* 
 #* SBSilentToggle is distributed in the hope that it will be useful,
 #* but WITHOUT ANY WARRANTY; without even the implied warranty of
 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #* GNU General Public License for more details.
 #* 
 #* You should have received a copy of the GNU General Public License
 #* along with SBSilentToggle.  If not, see <http://www.gnu.org/licenses/>.
 #*/
 
m_username=`whoami|grep .`
if [ "$m_username" != "root" ]
then
	echo "You must be logged in as root."
	exit
fi;

if [ ! -f /var/mobile/Library/SBSettings/Toggles/Silent/SilentToggle.pid ]
then
	echo "SilentToggle On" > /var/mobile/Library/SBSettings/Toggles/Silent/SilentToggle.pid
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOff/CategoriesThatShareVolumes.plist /System/Library/PrivateFrameworks/Celestial.framework/CategoriesThatShareVolumes.plist
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOff/CategoryMinimumVolumes.plist /System/Library/PrivateFrameworks/Celestial.framework/CategoryMinimumVolumes.plist
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOff/RegionalVolumeLimits.plist /System/Library/PrivateFrameworks/Celestial.framework/RegionalVolumeLimits.plist
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOff/SystemSoundBehaviour.plist /System/Library/PrivateFrameworks/Celestial.framework/SystemSoundBehaviour.plist
	/var/mobile/Library/SBSettings/Toggles/Silent/ringtonevolumehelper /var/mobile/Library/SBSettings/Toggles/Silent/SilentToggleVolumeSettings.plist `/var/mobile/Library/SBSettings/Toggles/Silent/ringtonevolumehelper /var/mobile/Library/Preferences/com.apple.celestial.plist`
	/var/mobile/Library/SBSettings/Toggles/Silent/ringtonevolumehelper /var/mobile/Library/Preferences/com.apple.celestial.plist -10000000000
else
	rm /var/mobile/Library/SBSettings/Toggles/Silent/SilentToggle.pid
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOn/CategoriesThatShareVolumes.plist /System/Library/PrivateFrameworks/Celestial.framework/CategoriesThatShareVolumes.plist
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOn/CategoryMinimumVolumes.plist /System/Library/PrivateFrameworks/Celestial.framework/CategoryMinimumVolumes.plist
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOn/RegionalVolumeLimits.plist /System/Library/PrivateFrameworks/Celestial.framework/RegionalVolumeLimits.plist
	cp /var/mobile/Library/SBSettings/Toggles/Silent/SoundOn/SystemSoundBehaviour.plist /System/Library/PrivateFrameworks/Celestial.framework/SystemSoundBehaviour.plist
	/var/mobile/Library/SBSettings/Toggles/Silent/ringtonevolumehelper /var/mobile/Library/Preferences/com.apple.celestial.plist `/var/mobile/Library/SBSettings/Toggles/Silent/ringtonevolumehelper /var/mobile/Library/SBSettings/Toggles/Silent/SilentToggleVolumeSettings.plist`
fi;

chown mobile:mobile /var/mobile/Library/Preferences/com.apple.celestial.plist

launchctl unload /System/Library/LaunchDaemons/com.apple.mediaserverd.plist
launchctl load /System/Library/LaunchDaemons/com.apple.mediaserverd.plist
